Handling Report Viewer events
The Report Viewer control allows you to write custom code for several events relating to user interaction with both the control window and the report displayed. For instance, if you design a drill down report using the Report Designer Component, your users are likely to want to drill down on detail data. You can provide custom handling of such an event by writing code fort the DrillOnGroup event.
To add event procedures to the Report Viewer control for the DrillOnGroup and PrintButtonClicked events:
- In the Visual Basic Project window, select the Form containing the Report Viewer control.
- Click the View Code button in the toolbar for the Project window. A code window for the form appears.
- In the drop-down list box at the upper left hand corner of the code window, select the CRViewer1 control. (This name will appear different if you changed the Name property of the control in the Properties window.)
- In the drop-down list box at the upper right corner of the code window, select the DrillOnGroup event. A procedure appears for handling the event.
- Add the following code to the DrillOnGroup event procedure:
Private Sub CRViewer1_DrillOnGroup(GroupNameList As Variant, _
ByVal DrillType As CRVIEWERLibCtl.CRDrillType, UseDefault As Boolean)
MsgBox "You're drilling down on the " & GroupNameList(0) & " group!"
End Sub
- In the drop-down list box at the upper right of the code window, select the PrintButtonClicked event. A new procedure appears for this event.
- Add the following code for the new event:
Private Sub CRViewer1_PrintButtonClicked(UseDefault As Boolean)
MsgBox "You clicked the Print button!"
End Sub
The DrillOnGroup event is triggered when a user double-clicks on a chart, on a map, or on a report summary field. The code added to the event procedure will display a message box with the name of the group. The PrintButtonClicked event is fired if the user clicks the print button on the Report Viewer window. Note that any code added to these event handlers replaces the default action of the event. A more practical use of these events would be to display custom dialogs or perform other report related calculations and procedures.